package util.project.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

/**
 * Created by MondaDev01 on 2017/11/13.
 */
public abstract class DaoImpl extends HibernateDaoSupport {
    protected SessionFactory sessionFactory;
    protected Session session;


    public void setSession(Session session){
        this.session = session;
    }

    //old mode
    public Session getSession() {
        //事务必须是开启的(Required)，否则获取不到
        if(sessionFactory != null && sessionFactory.getCurrentSession() != null) {
            return sessionFactory.getCurrentSession();
        } else {
            return session;
        }
    }
}
